package dao

import (
	"gorm.io/gorm"
	"gotham-plan-manage/internal/infra/database/mysql/plan/po"
)

/*
   @author:zhongyang
   @date:2023/4/5
   @description:计划报告数据库操作
*/

type PlanReportDao struct {
}

func NewPlanReportDao() *PlanReportDao {
	return &PlanReportDao{}
}

func (p *PlanReportDao) DeleteByPlanId(db *gorm.DB, planReportPO *po.PlanReportPO) error {
	return db.Where("plan_id", planReportPO.PlanId).Delete(&planReportPO).Error
}

func (p *PlanReportDao) Save(db *gorm.DB, reportPO *po.PlanReportPO) error {
	return db.Create(&reportPO).Error
}

func (p *PlanReportDao) GetOne(db *gorm.DB, planId string) (*po.PlanReportPO, error) {
	var res *po.PlanReportPO
	if err := db.Where("plan_id = ?", planId).First(&res).Error; err != nil {
		return nil, err
	}
	return res, nil
}
